package I.O;
//输出n.java的文件内容
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class IOprintf {

	public static void main(String[] args) {
		File f = new File("n.java");
		System.out.println(f.isFile());
		System.out.println(f.getParent());//父路径   分相对/绝对
		System.out.println(f.getAbsolutePath());
		System.out.println(f.getName());
	
		File f2 = f.getAbsoluteFile();
		InputStream in = null;
		try {
			in = new FileInputStream(f);
			byte[] b = new byte[1024];
			//一个字符的字节数影响了输出
			int n;
			try {
				while (-1 != (n = in.read(b))) {
					String info = new String(b, 0, n);
					System.out.println(info);
				}
			} catch (IOException e) {
				e.printStackTrace();
				System.out.println(f.getAbsolutePath() + "文件不存在");
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != in) {
					in.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

}
